﻿using System;
using UnityEngine;

namespace CornerMemo
{
    /// <summary>
    /// 键盘绑定。
    /// </summary>
    public class KeyboardBinding : MonoBehaviour
    {
        private void OnEnable()
        {
            $"绑定键盘事件。".InfoColor(Color.yellow);
            EventCenter.SubscribeUnique(KeyboardDownEventArgs.EventId, BindKeyDown);
            EventCenter.SubscribeUnique(KeyboardUpEventArgs.EventId, BindKeyUp);
            EventCenter.SubscribeUnique(KeyboardHoldEventArgs.EventId, BindKeyHold);
        }

        private void OnDisable()
        {
            $"取消绑定键盘事件。".InfoColor(Color.yellow);
            EventCenter.Unsubscribe(KeyboardDownEventArgs.EventId, BindKeyDown);
            EventCenter.Unsubscribe(KeyboardUpEventArgs.EventId, BindKeyUp);
            EventCenter.Unsubscribe(KeyboardHoldEventArgs.EventId, BindKeyHold);
        }
        
        private void BindKeyHold(object sender, GameEventArgs e) { }

        private void BindKeyUp(object sender, GameEventArgs e) { }

        private void BindKeyDown(object sender, GameEventArgs e)
        {
            if (e is not KeyboardDownEventArgs args)return;
            if (args.KeyCode == KeyCode.Q)
            {
                $"按下Q键 打开UI".InfoColor(Color.yellow);
                EnumUIForm.UIListForm.OpenUIForm();
            }
            if (args.KeyCode == KeyCode.W)
            {
                $"按下W键 打开UI".InfoColor(Color.yellow);
                EnumUIForm.MyNewUIForm.OpenUIForm("按下W键 打开UI");
            }
        }
        
        
    }
}